/*
 * Copyright (c) 2022  by Junzhao
 * THIS FILE IS PART OF JAVASE Song Huongkang PROJECT
 * All Rights Reserved.
 */

package 实现Runnable接口;
/**
 * @description 创建多线程的方式之二
 *                  实现Runnable接口
 *                  实现run()方法
 *                  创建实例
 *                  将此实例作为参数传递给Thread的构造方法构造一个Thread对象
 *                  使用该对象调用相关方法
 *
 * @author 俊昭
 * @date 2022/4/12
*/
public class RunnableTest {
    public static void main(String[] args) {
        MyRunnable mr1 = new MyRunnable();
        Thread t1 = new Thread(mr1,"测试线程1");
        t1.start();
        Thread t2 = new Thread(mr1,"测试线程2");
        t2.start();

        Thread.currentThread().setName("主线程");

        for (int i = 0; i < 100; i++) {
            if (i % 2==0){
                System.out.println(Thread.currentThread().getName() +" "+i);
            }
        }

    }
}
class MyRunnable implements Runnable{

    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            if (i % 2==0){
                System.out.println(Thread.currentThread().getName()+" "+i);
            }
        }

    }
}